var express = require('express');
var router = express.Router();
const soonsService = require('../service/soonsService');
/* GET users listing. */
// router.get('/', function (req, res, next) {
//   res.send('respond with a resource');
// });

// 增加
router.post('/', async function (req, res) {
  let {films} = req.body;
  let data = await soonsService.insert({films});
  console.log("films:"+films);
  res.send(data);
});

// 查询
router.get('/', async function (req, res) {
  let { type, value, current, pageSize } = req.query;
  let searchParams = {};
  searchParams[type] = value;
  // console.log(searchParams[type]);
  let data = await soonsService.find({ current: current || 1, pageSize: pageSize || 5 }, searchParams);
   console.log(data);
  res.send(data);
 
});

// ID查询
router.get('/:id', async function (req, res) {
  let { id } = req.params;
  let data = await soonsService.findById(id);
  res.send(data);
});
// 删除
router.delete('/:id', async function (req, res) {
  let { id } = req.params;
  let data = await soonsService.delete(id);
  res.send(data);
});

// 修改
// router.put('/:id', async function (req, res) {
//   let {id} = req.params
// //   let { name, gender, age } = req.body;
//   let data = await hotShowService.update({ _id: id});
//   res.send(data);
// });
// router.post('/usernameExist', async function (req, res) {
//   let { name } = req.body;
//   let data = await hotShowService.findByUsername(name);
//   if (data.length > 0) {
//     res.send({ status: 0 });
//   } else {
//     res.send({ status: 1 });
//   }
// });
module.exports = router;
